import Env.EnvMain as en
import Net_Model.Tools.TextTools as txt
import socketserver as sos
import socket as soc
import Net_Model.Tools.XMLTool as xml
import Net_Model.Tools.Message_Class as mess

def get_para_env(para_soc):
    t=txt.text()
    list_conm=['n_friend','n_enemy']
    para=[]
    for i in list_conm:
        para.append(t.pick_conm(para_soc,i))
    return para

def Run(Para_env):
    env = en.ACEnv(Para_env[0], Para_env[1])
    program = [env.reset, env.FirstStep, env.step, env.render]

class Run_server(sos.StreamRequestHandler):
    def handle(self):
        print('已连接：'+self.client_address)
        Para_env=self.rfile.readline().decode()
        env=en.ACEnv(Para_env[0], Para_env[1])
        self.wfile.write('开始仿真')





if __name__=='__main__':
    #######启动服务器######################
    doc = xml.XMLTools()
    host = soc.gethostbyname(soc.gethostname())
    port = int(doc.Read_xml('../Config.xml', 'Socket_Server_Config/Port_Address')) if \
        doc.Xml_Exist('../Config.xml') else 51423
    server=sos.ThreadingTCPServer((host,port),Run_server)  # 多进程处理
    print('等待连接')
    server.serve_forever()
    ######################################

